package com.lizard.schedule.manager;

import com.google.android.gms.wearable.DataItem;
import com.google.android.gms.wearable.Node;
import com.lizard.schedule.model.WearSchedule;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wangyiqian on 16/6/12.
 */

public class ObserverManager {

    private static ObserverManager instance;

    private List<ObserverIfaces.HandsetConnectChangedListener> handsetConnectChangedListeners = new ArrayList<>();

    private List<ObserverIfaces.OnSyncSchedulesListener> onSyncSchedulesListeners = new ArrayList<>();

    private ObserverManager(){

    }

    synchronized public static ObserverManager getInstance(){
        if(instance == null){
            instance = new ObserverManager();
        }
        return instance;
    }

    public void addOnSyncSchedulesListener(ObserverIfaces.OnSyncSchedulesListener listener){
        onSyncSchedulesListeners.add(listener);
    }

    public void removeOnSyncSchedulesListener(ObserverIfaces.OnSyncSchedulesListener listener){
        onSyncSchedulesListeners.remove(listener);
    }

    public void notifyOnSyncSchedulesListeners(List<WearSchedule> wearSchedules){
        for(ObserverIfaces.OnSyncSchedulesListener listener : onSyncSchedulesListeners){
            listener.onSync(wearSchedules);
        }
    }

    public void addHandsetConnectChangedListener(ObserverIfaces.HandsetConnectChangedListener listener){
        handsetConnectChangedListeners.add(listener);
    }

    public void removetHandsetConnectChangedListener(ObserverIfaces.HandsetConnectChangedListener listener){
        handsetConnectChangedListeners.remove(listener);
    }

    public void notifyHandsetConnectChangedListeners(boolean connected, Node peer){
        for(ObserverIfaces.HandsetConnectChangedListener listener : handsetConnectChangedListeners){
            listener.onConnectChanged(connected, peer);
        }
    }

}
